package model

import (
	"manager/model/entity"
	"manager/model/po"
)

type RouteListCreateRequest struct {
	EbikeId int64 `json:"ebike_id"`

	StartName string `json:"start_name"`

	StartCoordinate po.Point `json:"start_coordinate"`

	EndName string `json:"end_name"`

	EndCoordinate po.Point `json:"end_coordinate"`

	Mileage int `json:"mileage"`

	MaxSpeed int `json:"max_speed"`

	StartTime int `json:"start_time"`

	EndTime int `json:"end_time"`

	UserId   int64 `json:"user_id"`
	AvgSpeed int   `json:"avg_speed"`

	TrackList []po.GpsLocation `json:"track_list"`

	City string `json:"city"`
}

type RouteListUpdateRequest struct {
	Id int64 `json:"id"`

	EbikeId *int64 `json:"ebike_id"`

	StartName *string `json:"start_name"`

	StartCoordinate *po.Point `json:"start_coordinate"`

	EndName *string `json:"end_name"`

	EndCoordinate *po.Point `json:"end_coordinate"`

	Mileage *int `json:"mileage"`

	MaxSpeed *int `json:"max_speed"`

	StartTime *int `json:"start_time"`

	EndTime *int `json:"end_time"`

	AvgSpeed *int `json:"avg_speed"`

	City *string `json:"city"`

	IsFinish *int `json:"is_finish"`

	List po.Array[po.GpsLocation] `gorm:"column:list;type:JSON" json:"list"`

	CreatedAt int64 `json:"created_at"`
}

type RouteListListRequest struct {
	Index int `json:"index"`
	Size  int `json:"size"`

	Id int64 `json:"id"`

	EbikeId int64 `json:"ebike_id"`
	UserId  int64 `json:"user_id"`

	StartName string `json:"start_name"`

	StartCoordinate po.Point `json:"start_coordinate"`

	EndName string `json:"end_name"`

	EndCoordinate po.Point `json:"end_coordinate"`

	Mileage int `json:"mileage"`

	MaxSpeed int `json:"max_speed"`

	StartTime int `json:"start_time"`

	EndTime int `json:"end_time"`
}

type RouteListListResponse struct {
	Total int              `json:"total"`
	List  []*RouteListInfo `json:"list"`
}

type RouteListInfoRequest struct {
	Id int64 `json:"id"`
}

type RouteListInfo struct {
	Id int64 `json:"id"`

	UserId int64 `json:"user_id"`

	EbikeId int64 `json:"ebike_id"`

	StartName string `json:"start_name"`

	StartCoordinate po.Point `json:"start_coordinate"`

	EndName string `json:"end_name"`

	EndCoordinate po.Point `json:"end_coordinate"`

	TrackList po.Array[po.GpsLocation] `json:"track_list"`

	Mileage int `json:"mileage"`

	AvgSpeed int `json:"avg_speed"`

	MaxSpeed int `json:"max_speed"`

	StartTime int `json:"start_time"`

	EndTime int `json:"end_time"`

	City string `json:"city"`

	CreatedAt int64 `json:"created_at"`

	UpdatedAt int64 `json:"updated_at"`
}

type RouteListDeleteRequest struct {
	Id      int64  `json:"id"`
	EbikeId *int64 `json:"ebike_id"`
	UserId  *int64 `json:"user_id"`
}

func RouteListsEntityToDto(routeLists []*entity.RouteList) []*RouteListInfo {
	out := make([]*RouteListInfo, 0, len(routeLists))
	for _, c := range routeLists {
		out = append(out, RouteListEntityToDto(c))
	}
	return out
}

func RouteListEntityToDto(e *entity.RouteList) *RouteListInfo {
	return &RouteListInfo{

		Id: e.Id,

		UserId: e.UserId,

		EbikeId: e.EbikeId,

		StartName: e.StartName,

		StartCoordinate: e.StartCoordinate,

		EndName: e.EndName,

		EndCoordinate: e.EndCoordinate,

		TrackList: e.List,

		Mileage: e.Mileage,

		AvgSpeed: e.AvgSpeed,

		MaxSpeed: e.MaxSpeed,

		StartTime: e.StartTime,

		EndTime: e.EndTime,
		City:    e.City,

		CreatedAt: e.CreatedAt,

		UpdatedAt: e.UpdatedAt,
	}
}
